package com.efuture.servlet.simplelogindemo.dao;

import com.efuture.servlet.simplelogindemo.domian.User;
import com.efuture.servlet.simplelogindemo.utils.JdbcUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class UserDao {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(JdbcUtils.getDataSource());
    public User login(User loginUser){
        try{
            System.out.println(loginUser);
            String sql = "select * from user where username = ? and password = ?";
            User user = jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<User>(User.class),loginUser.getUsername(),loginUser.getPassword());
            if(null!=user){
                return user;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
